<?php

// $Id: both.php 3 2010-05-27 16:25:49Z alistair.mills@btinternet.com $

   session_start();

include ("functions.php");

   $thisscript = $HTTP_SERVER_VARS["PHP_SELF"]; // link to this php file
   $path_parts = pathinfo($thisscript);
   $root_dir   = $path_parts["dirname"];
   $host       = "http://".$HTTP_SERVER_VARS['SERVER_NAME'];

   $thisscript = $HTTP_SERVER_VARS["PHP_SELF"]; // link to this php file
   $path_parts = pathinfo($thisscript);
   $root_dir   = $path_parts["dirname"];
   $host       = "http://".$HTTP_SERVER_VARS['SERVER_NAME'];

   if (isset($_SESSION["history"])) {
       $history = $_SESSION["history"];
   }  else {
       $_SESSION["history"] = $history;
   }

   $sort = "";
   if ($_SERVER['REQUEST_METHOD'] == "GET") {
       if (isset($_GET["sort"])) $sort = $_GET["sort"];
   }

   $year         = 2001;
   $category     = '';
   $month        = 0;
   $query        = "";
   $paragraph    = "";

   $db = db_open($host);

   if ($db) {

      $translators = build_index ("SELECT * FROM translators","trans",  "translator" );
      $months      = build_index ("SELECT * FROM months",     "mon",    "month" );
      $categories  = build_index ("SELECT * FROM categories", "cat",    "category" );


      if ($_SERVER['REQUEST_METHOD'] == "GET") {
         if (isset($_GET["query"]))         $query         = $_GET["query"];
         if (isset($_GET["cat"]))           $cat           = $_GET["cat"];
         if (isset($_GET["month"]))         $month         = $_GET["month"];
         if (isset($_GET["year"]))          $year          = $_GET["year"];
         if (isset($_GET["paragraph"]))     $paragraph     = $_GET["paragraph"];
         if (isset($_GET["pres"]))          $pres          = $_GET["pres"];
      }

       $sql =
          'SELECT * FROM paragraphs where category = "'. $cat .'" and year = ' .$year. ' and month = ' .$month .' and number = 1 and language = "english" ';

       $sql_        = addslashes($sql);
       $sql__       = get_magic_quotes_runtime() ? $sql_ : $sql;
       $reponse     = mysql_query($sql__) or die(mysql_error());

       $translator  = "unknown";
       $title       = "unknown";
       $text        = "";

       $un_film     = mysql_fetch_assoc($reponse);
       $title       = $un_film["title"];
       $trans       = $un_film["translator"];
       $date        = $un_film["file_date"];

       mysql_free_result($reponse);

       $translator  = $translators [$trans];
       $category    = $categories  [$cat];
       $m           = sprintf("%02d", (int) $month);
       $mois        = $months      [$m];

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta name="description" content="French Lessons">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>La Guinguette - <?php $p = ($paragraph == "") ? "" : " - " . $paragraph; echo "$year - $mois - $category $p "; ?></title>
    <link href="../../style.css" rel="stylesheet" type="text/css">

<style type="text/css">
<!--
p {
    color: Black;
}
-->
</style>

</head>

<body bgcolor="#FFFFFF" background="../back.gif" text="#008000" link="#0000FF" vlink="#0000FF">
<a href="./index.php"><img src="../../up.gif" alt="up" width="36" height="18"></a>
<h1>Articles de La Guinguette - <?php echo "$year - $mois - $category"; ?> </h1>

<?php
include ("navigate_table.php");

       echo '<br>';

       if ($_SERVER['REQUEST_METHOD'] == "GET") {
          if (isset($_GET["query"]))         $query         = $_GET["query"];
          if (isset($_GET["cat"]))           $category      = $_GET["cat"];
          if (isset($_GET["month"]))         $month         = $_GET["month"];
          if (isset($_GET["year"]))          $year          = $_GET["year"];
          if (isset($_GET["paragraph"]))     $paragraph     = $_GET["paragraph"];
       }

       $q_french    = "language = 'french'";
       $q_english   = "language = 'english'";
       $q_language  = $q_french;
       $q_and       = " AND ";
       $q_year      =      " year = ".$year;
       $q_month     =     " month = ".$month;
       $q_category  =  " category = '".$category."'";
       $q_paragraph = "    number = ".$paragraph;
       $q_where     = " WHERE ";


       $sql         = "select count(*) FROM paragraphs WHERE year = 2003 AND month = 05 AND category = 'cul' and language = 'french'";
       $q_select    = "select count(*) FROM paragraphs ";
       $sql         = $q_select
                      . $q_where
                      . $q_year .
               ( (     $month == 0 )  ? '' : ($q_and . $q_month)) .
               ( (  $category == '' ) ? '' : ($q_and . $q_category)) .
                                              $q_and . $q_french ;
       $sql_        = addslashes($sql);
       $sql__       = get_magic_quotes_runtime() ? $sql_ : $sql;
       $reponse     = mysql_query($sql__) or die(mysql_error());
       $max_fr      = mysql_fetch_assoc ($reponse);
       $sql         = $q_select
                      . $q_where
                      . $q_year .
               ( (     $month == 0 )  ? '' : ($q_and . $q_month)) .
               ( (  $category == '' ) ? '' : ($q_and . $q_category)) .
                                              $q_and . $q_english ;
       $sql_        = addslashes($sql);
       $sql__       = get_magic_quotes_runtime() ? $sql_ : $sql;
       $reponse     = mysql_query($sql__) or die(mysql_error());
       $max_en      = mysql_fetch_assoc ($reponse);
       $max_en_b    = $max_en["count(*)"];
       $max_b       = $max_en_b > $max_fr_b ? $max_en_b : $max_fr_b;

       $para        = $paragraph == '' ? '2' : $paragraph;
       $p_prev      = sprintf("%02d", (int) $para - 1);
       $p_next      = sprintf("%02d", (int) $para + 1);
       echo '<table border="1" bordercolor="#ffffff"><tr>';

       echo '<td><a title="article"   href="both.php?month=' . $month .
                                                '&amp;year=' . $year  .
                                                 '&amp;cat=' . $category .
                                                         '">^^ article ^^   </a></td>';
       if ($p_prev > 0)
       echo '<td><a title="anterieur" href="both.php?month=' . $month .
                                                '&amp;year=' . $year  .
                                                 '&amp;cat=' . $category .
                                           '&amp;paragraph=' . $p_prev .
                               '"><< paragraphe pr&eacute;c&eacute;dent (' . $p_prev .')  </a></td>';
       if ($p_next < $max_b+1)
       echo '<td><a title="ulterieur" href="both.php?month=' . $month .
                                                '&amp;year=' . $year  .
                                                 '&amp;cat=' . $category .
                                           '&amp;paragraph=' . $p_next .
                                 '" >paragraphe suivant (' . $p_next .')>></a></td>';
       // echo '<td>paragraphe max (' . $max_b .')</td>';
       echo '</tr></table>';

       $sql = ($query == "") ?
          "SELECT paragraph FROM paragraphs WHERE year = 2001 and category = 'act' and month = 2 order by number, language"
       :
          $query
       ;
       $q_select    = " SELECT number, paragraph, language FROM paragraphs ";
       $q_order     = " ORDER BY number, language DESC";

       $sql         = $q_select
                      . $q_where
                      . $q_year .
               ( (     $month == 0 )  ? '' : ($q_and . $q_month)) .
               ( (  $category == '' ) ? '' : ($q_and . $q_category)) .
               ( ( $paragraph == '' ) ? '' : ($q_and . $q_paragraph)) .
                        $q_order;

       $sql_        = addslashes($sql);
       $sql__       = get_magic_quotes_runtime() ? $sql_ : $sql;
       $reponse     = mysql_query($sql__) or die(mysql_error());

       echo '<table border="1" bordercolor="#000000">';

       $right       =  "<p>&nbsp;</p>";
       $left        =  "<p>&nbsp;</p>";
       $line        =  "<tr>";
       $this_one    = ( $paragraph == '' ) ? 1 : $paragraph ;

       while ($resp = mysql_fetch_assoc ($reponse)) {
             if (!($this_one==$resp["number"])) {
                 $line    .= '<td width="50%">' . $left .  '</td>';
                 $line    .= '<td width="50%">' . $right . '</td>';
                 $line    .=  "</tr>";
                 echo $line;
                 $this_one =$resp["number"];
                 $right    =  "<p>&nbsp;</p>";
                 $left     =  "<p>&nbsp;</p>";
                 $line     =  "<tr>";
            }
            if ($resp["language"] == "french")  $left  = $resp["paragraph"];
            if ($resp["language"] == "english") $right = $resp["paragraph"];
       }
       $line    .= '<td width="50%">' . $left .  '</td>';
       $line    .= '<td width="50%">' . $right . '</td>';
       $line    .=  "</tr>";
       echo $line;

       mysql_free_result($reponse);

       echo '</table>';
    }
?>

<hr>
      <p lang="EN">With questions or for more information, please contact Alistair Mills <a href="mailto:alistair.mills@btinternet.com"> alistair.mills@btinternet.com</a><br>
      Updated <!-- #BeginDate format:Sw1 --> Sunday 14th December 2008  <!-- #EndDate --></p>
      <a href="http://validator.w3.org/check?uri=referer">
        <img
        src="http://www.w3.org/Icons/valid-html401-blue"
        alt="Valid HTML 4.01 Transitional" height="31" width="88">
      </a>


<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2273668-1";
urchinTracker();
</script>

</body>
</html>
